//
//  XYSegementViewController.m
//  XYAuto
//
//  Created by 小萌 on 2016/12/28.
//  Copyright © 2016年 Raymond~. All rights reserved.
//

#import "XYSegementViewController.h"

@interface XYSegementViewController ()<XYSegementViewDelegate,XYSegementViewDataSource>

@end

@implementation XYSegementViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.segementView];

}
- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
}
- (XYSegementView *)segementView
{
    if (!_segementView) {
        _segementView = [XYSegementView segementViewWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 24 - SafeAreaBottomHeight)];
        _segementView.delegate = self;
        _segementView.dataSource = self;
        _segementView.parentVC = self;
    }
    return _segementView;
}
- (void)setViewControllers:(NSArray *)viewControllers
{
    if (_viewControllers != viewControllers) {
        _viewControllers = viewControllers;
    }
    [self.segementView reloadSegementView];
}
- (NSInteger)numberOfRowsInXYSegementView:(UIView *)segementView
{
    return self.viewControllers.count;
}
- (UIViewController *)segementView:(XYSegementView *)segementView rowAtIndexPath:(NSInteger)indexPath
{
    return self.viewControllers[indexPath];
}
- (void)segementView:(XYSegementView *)segementView didSelectRowAtIndexPath:(NSInteger)indexPath;
{
    _selectedViewController = self.viewControllers[indexPath];
    [self segementViewController:self didSelectRowAtIndexPath:indexPath];
}
- (void)segementViewController:(XYSegementViewController *)viewController didSelectRowAtIndexPath:(NSInteger)indexPath
{
    YTBaseController * oldVC = self.viewControllers[self.segementView.smallScrollView.preIndex];
    
    YTBaseController * newVC = self.viewControllers[indexPath];
    if (oldVC != newVC) {
        [oldVC viewDidDisappear:YES];
        [newVC viewDidAppear:YES];
    }
}
//禁用KVC修改readonly属性的值
+ (BOOL)accessInstanceVariablesDirectly
{
    return NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
